package com.download.web.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.download.web.entity.BusArticleComment;
import com.download.web.entity.model.CommentModel;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * @description:
 * @author: cmy
 * @create: 2019-02-21 19:44
 **/
public interface BusArticleCommentMapper extends BaseMapper<BusArticleComment> {

    //查找文章一级评论
    @Select(" SELECT c.content,c.id commentId,c.create_time,u.user_name,u.head_img userImg from bus_article_comment c  " +
            " LEFT JOIN sys_user u on c.user_id=u.id " +
            " where c.article_id=${artId} " +
            " and obj_type =${objType} and c.states=false " +
            " limit ${pageIndex},${pageSize} ")
    List<CommentModel> commentList(@Param("artId")Integer artId, @Param("pageIndex")Integer pageIndex, @Param("pageSize")Integer pageSize,@Param("objType")Integer objType);
    //查找文章一级评论数量
    @Select(" SELECT count(1) from bus_article_comment c  " +
            " where c.article_id=${artId} and obj_type =${objType} and c.states=false " )
    Integer articleCcommentCount(@Param("artId")Integer artId ,@Param("objType")Integer objType);

    /**
     * 按评论id查找评论回复前三条
     * @param commentId 上级评论id
     * @param pageIndex
     * @param pageSize
     * @return
     */
    @Select(" SELECT c.content,c.id commentId,c.create_time,u.user_name,u.head_img userImg from bus_article_comment c  " +
            " LEFT JOIN sys_user u on c.user_id=u.id " +
            " where c.parent_id=${commentId} and c.states=false " +
            " limit ${pageIndex},${pageSize} ")
    List<CommentModel> commentReplyList(@Param("commentId")Integer commentId, @Param("pageIndex")Integer pageIndex, @Param("pageSize")Integer pageSize);
    //按评论id查找评论回复数量
    @Select(" SELECT count(1) from bus_article_comment c  " +
            " where c.parent_id=${commentId} and c.states=false " )
    Integer commentReplyCount(@Param("commentId")Integer commentId);

    @Select("SELECT * FROM bus_article_comment as c ${sql} LIMIT #{pageIndex},#{pageSize}")
    List<Map<String,Object>> selectAllPage(@Param("sql")String sql,@Param("pageIndex")Integer pageIndex, @Param("pageSize")Integer pageSize);
}
